|
|
|
|
|
|
|
Because you did not specify a value for the Recordset object's CursorType property, it was set to the default value of adOpenForwardOnly. The ramifications of the CursorType property are discussed shortly; but for now just remember that a "forward only" cursor does not support MovePrevious and MoveLast navigation methods. |
|
|
|
|
|
|
|
|
As an example of recordset navigation, you will create a project that uses the navigation methods. To get started, create a new Standard EXE project with a list box named lstData, three command buttons (cmdPrevious, cmdNext, and cmdJump), and a text box named txtJump. |
|
|
|
|
|
|
|
|
The sample program runs a query against the BIBLIO database and then allows the user to execute the navigation methods to browse the recordset, much like you did with the Data control. The code for the sample project is shown in Listing 28.2. |
|
|
|
|
|
|
|
|
Listing 28.2 ADONAV.ZIPUsing Recordset Navigation Methods |
|
|
|
|
|
|
|
|
Option Explicit
Dim rs As ADODB.Recordset
Private Sub Form_Load()
'FILL THE RECORDSET OBJECT RS
Set rs = New ADODB.Recordset
rs.CursorType = adOpenStatic
rs.Source = "Select * from Publishers"
rs.Open , "DSN=BIBLIO"
DisplayCurrentRecord
End Sub
Sub DisplayCurrentRecord()
Dim i As Integer
Dim s As String
If rs.BOF Then rs.MoveFirst
If rs.EOF Then rs.MoveLast
lstData.Clear
For i = 0 To rs.Fields.Count - 1
s = rs.Fields(i).Name & ": " & rs.Fields(i)
lstData.AddItem s
Next i
End Sub
Private Sub cmdJump_Click()
rs.Move Val(txtJump)
DisplayCurrentRecord
End Sub
Private Sub cmdNext_Click()
rs.MoveNext
DisplayCurrentRecord
End Sub
Private Sub cmdPrevious_Click()
rs.MovePrevious
DisplayCurrentRecord
End Sub |
|
|
|
|
|